package com.jcc.springcloud.controller;

import com.jcc.springcloud.result.CommonResult;
import com.jcc.springcloud.service.LoginService;
import com.jcc.springcloud.user.UserDo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Slf4j
public class LoginController {
    @Resource
    private LoginService loginService;

    @ResponseBody
    @PostMapping(value = "/login")
    public CommonResult login(@RequestBody UserDo userDo){
        UserDo userByName = loginService.findUserByName(userDo);
        if(userByName == null){
            return new CommonResult(444,"登录失败，用户名未注册",null);
        }else{
            UserDo userByPwd = loginService.findUserByPwd(userDo);
            if(userByPwd == null){
                return new CommonResult(444,"登录失败，密码错误",null);
            }else {
                return new CommonResult(200,"登录成功",null);
            }
        }
    }
}
